import {
  BaseEntity,
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Category } from './category.entity';

@Entity()
export class Product extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'varchar', length: 255, comment: 'offerId', nullable: true })
  offerId: string;

  @Column({ type: 'varchar', length: 255, comment: '名称' })
  name: string;

  @Column({ type: 'varchar', length: 255, comment: '主图' })
  mainImage: string;

  @Column({ type: 'text', comment: '图片' })
  images: string;

  @Column({ type: 'text', comment: '描述' })
  description: string;

  @Column({ type: 'text', comment: 'sku' })
  sku: string;

  @Column({ type: 'int', comment: '库存', default: 0 })
  stock: number;

  @Column({ type: 'decimal', precision: 10, scale: 2, comment: '价格' })
  price: number;

  @Column({ type: 'int', comment: '销量', default: 0 })
  sales: number;

  @Column({ type: 'int', comment: '状态', default: 0 })
  status: number;

  @Column({ type: 'int', comment: '排序', default: 0 })
  sort: number;

  @Column({
    type: 'decimal',
    precision: 10,
    scale: 2,
    comment: '成本',
    default: 0.0,
  })
  cost: number;

  @ManyToOne(() => Category, (category) => category.products)
  category: Category;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;

  @DeleteDateColumn({ nullable: true })
  deleteTime: Date;
}
